Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ExcelManager = require("ExcelManager");
var $2MyUtils = require("MyUtils");
var $2DataManager = require("DataManager");
var $2MoneyPanelUI = require("MoneyPanelUI");
var $2UIManager = require("UIManager");
var $2UpgradeUI = require("UpgradeUI");
var def_UserDataManager = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.is_new = true;
    this._userDataKey = "userDataZombies";
    this.init();
  }
  babel_createClass(_ctor, [{
    key: "init",
    value: function init() {
      this._userData = {
        lastYear: 0,
        lastMonth: 0,
        lastDay: 0,
        scene: 0,
        shopInfo: [],
        shopHour: -1,
        bossLevel: [1],
        plantLevel: [],
        plantChip: [],
        plantLock: [1, 2, 21, 23],
        gold: 0,
        diamond: 0,
        level: 1,
        chapter: 1,
        signDay: 0,
        shopRefreshTimes: 0,
        freePlant: 0,
        signTimes: 0,
        newUser: true,
        drawGuide: false,
        bossGuide: false,
        shareReward: true,
        goldGain: 0,
        huangGuaGuide: false,
        upGradeGuide: false,
        upGradeGuide2: false,
        levelGuide: false,
        onlineInfo: [],
        onlineNum: 0,
        onlineTime: 0,
        taskInfo: [],
        timeInfo: [],
        time1Info: [],
        bwzjsInfo: [],
        bwzdaifuInfo: [],
        videoDrawTimes: 0,
        noCDGuide: false,
        extraGoldGuide: false
      };
    }
  }, {
    key: "getPlantChip",
    value: function getPlantChip(e) {
      null == this._userData.plantChip && (this._userData.plantChip = []);
      if (null == this._userData.plantChip[e - 1]) {
        this._userData.plantChip[e - 1] = 0;
        this.writeStorage();
      }
      return this._userData.plantChip[e - 1];
    }
  }, {
    key: "setPlantChip",
    value: function setPlantChip(e, t) {
      null == this._userData.plantChip && (this._userData.plantChip = []);
      null == this._userData.plantChip[e - 1] && (this._userData.plantChip[e - 1] = 0);
      this._userData.plantChip[e - 1] += t;
      this.writeStorage();
    }
  }, {
    key: "getPlantLevel",
    value: function getPlantLevel(e) {
      null == this._userData.plantLevel && (this._userData.plantLevel = []);
      if (null == this._userData.plantLevel[e - 1]) {
        this._userData.plantLevel[e - 1] = 1;
        this.writeStorage();
      }
      return this._userData.plantLevel[e - 1];
    }
  }, {
    key: "setPlantLevel",
    value: function setPlantLevel(e, t) {
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
      null == this._userData.plantLevel[e - 1] && (this._userData.plantLevel[e - 1] = 1);
      this._userData.plantLevel[e - 1] = t;
      a || this.writeStorage();
    }
  }, {
    key: "plantLock",
    get() {
      null == this._userData.plantLock && (this._userData.plantLock = [1, 2, 21]);
      return this._userData.plantLock;
    }
  }, {
    key: "getPlant",
    value: function getPlant(e) {
      if (this._userData.plantLock.includes(e)) {
        this.setPlantChip(e, 20);
      } else {
        this._userData.plantLock.push(e);
        $2DataManager.default.instance.newPlant.includes(e) || $2DataManager.default.instance.newPlant.push(e);
      }
      this.writeStorage();
    }
  }, {
    key: "videoDrawTimes",
    get() {
      null == this._userData.videoDrawTimes && (this._userData.videoDrawTimes = 0);
      return this._userData.videoDrawTimes;
    },
    set(e) {
      this._userData.videoDrawTimes = e;
      this.writeStorage();
    }
  }, {
    key: "onlineTime",
    get() {
      null == this._userData.onlineTime && (this._userData.onlineTime = 0);
      return this._userData.onlineTime;
    },
    set(e) {
      e > 300 && (e = 300);
      this._userData.onlineTime = e;
      this.writeStorage();
    }
  }, {
    key: "onlineNum",
    get() {
      null == this._userData.onlineNum && (this._userData.onlineNum = 0);
      return this._userData.onlineNum;
    },
    set(e) {
      this._userData.onlineNum = e;
      this.writeStorage();
    }
  }, {
    key: "huangGuaGuide",
    get() {
      null == this._userData.huangGuaGuide && (this._userData.huangGuaGuide = false);
      return this._userData.huangGuaGuide;
    },
    set(e) {
      this._userData.huangGuaGuide = e;
      this.writeStorage();
    }
  }, {
    key: "bossLevel",
    get() {
      if (null == this._userData.bossLevel) {
        this._userData.bossLevel = [1];
        this.writeStorage();
      }
      if (1 == this._userData.bossLevel) {
        this._userData.bossLevel = [1];
        this.writeStorage();
      } else if (2 == this._userData.bossLevel) {
        this._userData.bossLevel = [1, 2];
        this.writeStorage();
      } else if (3 == this._userData.bossLevel) {
        this._userData.bossLevel = [1, 2, 3], this.writeStorage();
      }
      return this._userData.bossLevel;
    }
  }, {
    key: "setbossLevel",
    value: function setbossLevel(e) {
      this._userData.bossLevel.push(e);
      this.writeStorage();
    }
  }, {
    key: "shareReward",
    get() {
      null == this._userData.shareReward && (this._userData.shareReward = true);
      return this._userData.shareReward;
    },
    set(e) {
      this._userData.shareReward = e;
      this.writeStorage();
    }
  }, {
    key: "noCDGuide",
    get() {
      null == this._userData.noCDGuide && (this._userData.noCDGuide = false);
      return this._userData.noCDGuide;
    },
    set(e) {
      this._userData.noCDGuide = e;
      this.writeStorage();
    }
  }, {
    key: "extraGoldGuide",
    get() {
      null == this._userData.extraGoldGuide && (this._userData.extraGoldGuide = false);
      return this._userData.extraGoldGuide;
    },
    set(e) {
      this._userData.extraGoldGuide = e;
      this.writeStorage();
    }
  }, {
    key: "bossGuide",
    get() {
      null == this._userData.bossGuide && (this._userData.bossGuide = false);
      return this._userData.bossGuide;
    },
    set(e) {
      this._userData.bossGuide = e;
      this.writeStorage();
    }
  }, {
    key: "drawGuide",
    get() {
      null == this._userData.drawGuide && (this._userData.drawGuide = false);
      return this._userData.drawGuide;
    },
    set(e) {
      this._userData.drawGuide = e;
      this.writeStorage();
    }
  }, {
    key: "shopRefreshTimes",
    get() {
      null == this._userData.shopRefreshTimes && (this._userData.shopRefreshTimes = 0);
      return this._userData.shopRefreshTimes;
    },
    set(e) {
      this._userData.shopRefreshTimes = e;
      this.writeStorage();
    }
  }, {
    key: "signTimes",
    get() {
      null == this._userData.signTimes && (this._userData.signTimes = 0);
      return this._userData.signTimes;
    },
    set(e) {
      this._userData.signTimes = e;
      this.writeStorage();
    }
  }, {
    key: "signDay",
    get() {
      null == this._userData.signDay && (this._userData.signDay = 0);
      return this._userData.signDay;
    },
    set(e) {
      this._userData.signDay = e;
      this._userData.signDay >= 7 && (this._userData.signDay = 0);
      this.writeStorage();
    }
  }, {
    key: "shopHour",
    get() {
      null == this._userData.shopHour && (this._userData.shopHour = -1);
      return this._userData.shopHour;
    },
    set(e) {
      this._userData.shopHour = e;
      this.writeStorage();
    }
  }, {
    key: "shopInfo",
    get() {
      null == this._userData.shopInfo && (this._userData.shopInfo = []);
      return this._userData.shopInfo;
    },
    set(e) {
      this._userData.shopInfo = e;
      this.writeStorage();
    }
  }, {
    key: "timeInfo",
    get() {
      null == this._userData.timeInfo && (this._userData.timeInfo = []);
      return this._userData.timeInfo;
    },
    set(e) {
      this._userData.timeInfo = e;
      this.writeStorage();
    }
  }, {
    key: "time1Info",
    get() {
      null == this._userData.time1Info && (this._userData.time1Info = []);
      return this._userData.time1Info;
    },
    set(e) {
      this._userData.time1Info = e;
      this.writeStorage();
    }
  }, {
    key: "bwzjsInfo",
    get() {
      null == this._userData.bwzjsInfo && (this._userData.bwzjsInfo = []);
      return this._userData.bwzjsInfo;
    },
    set(e) {
      this._userData.bwzjsInfo = e;
      this.writeStorage();
    }
  }, {
    key: "bwzdaifuInfo",
    get() {
      null == this._userData.bwzdaifuInfo && (this._userData.bwzdaifuInfo = []);
      return this._userData.bwzdaifuInfo;
    },
    set(e) {
      this._userData.bwzdaifuInfo = e;
      this.writeStorage();
    }
  }, {
    key: "changeshopInfo",
    value: function changeshopInfo(e, t) {
      this._userData.shopInfo[e] = t;
      this.writeStorage();
    }
  }, {
    key: "onlineInfo",
    get() {
      (null == this._userData.onlineInfo || this._userData.onlineInfo && 0 == this._userData.onlineInfo.length) && this.getonlineInfo();
      return this._userData.onlineInfo;
    },
    set(e) {
      this._userData.onlineInfo = e;
      this.writeStorage();
    }
  }, {
    key: "taskInfo",
    get() {
      (null == this._userData.taskInfo || this._userData.taskInfo && 0 == this._userData.taskInfo.length) && this.getTaskInfo();
      return this._userData.taskInfo;
    },
    set(e) {
      this._userData.taskInfo = e;
      this.writeStorage();
    }
  }, {
    key: "changeOnlineInfo",
    value: function changeOnlineInfo(e, t) {
      this._userData.onlineInfo[e] = t;
      this.writeStorage();
    }
  }, {
    key: "levelGuide",
    get() {
      null == this._userData.levelGuide && (this._userData.levelGuide = true);
      return this._userData.levelGuide;
    },
    set(e) {
      this._userData.levelGuide = e;
      this.writeStorage();
    }
  }, {
    key: "upGradeGuide2",
    get() {
      null == this._userData.upGradeGuide2 && (this._userData.upGradeGuide2 = false);
      return this._userData.upGradeGuide2;
    },
    set(e) {
      this._userData.upGradeGuide2 = e;
      this.writeStorage();
    }
  }, {
    key: "upGradeGuide",
    get() {
      null == this._userData.upGradeGuide && (this._userData.upGradeGuide = true);
      return this._userData.upGradeGuide;
    },
    set(e) {
      this._userData.upGradeGuide = e;
      this.writeStorage();
    }
  }, {
    key: "newUser",
    get() {
      null == this._userData.newUser && (this._userData.newUser = true);
      return this._userData.newUser;
    },
    set(e) {
      this._userData.newUser = e;
      this.writeStorage();
    }
  }, {
    key: "level",
    get() {
      null == this._userData.level && (this._userData.level = 1);
      return this._userData.level;
    },
    set(e) {
      this._userData.level = e;
      if (this._userData.level > 20) {
        this._userData.level = 1;
        this._userData.chapter++;
      }
      this.writeStorage();
    }
  }, {
    key: "chapter",
    get() {
      null == this._userData.chapter && (this._userData.chapter = 1);
      return this._userData.chapter;
    },
    set(e) {
      this._userData.chapter = e;
      this.writeStorage();
    }
  }, {
    key: "gold",
    get() {
      null == this._userData.gold && (this._userData.gold = 0);
      return this._userData.gold;
    },
    set(e) {
      this._userData.gold = e;
      $2MoneyPanelUI.default.instance && $2MoneyPanelUI.default.instance.refreshMoneyPanel();
      $2UIManager.default.instance.uiList.UpgradeUI && $2UIManager.default.instance.uiList.UpgradeUI.getComponent($2UpgradeUI.default).refreshMoneyPanel();
      this.writeStorage();
    }
  }, {
    key: "freePlant",
    get() {
      null == this._userData.freePlant && (this._userData.freePlant = 0);
      return this._userData.freePlant;
    },
    set(e) {
      this._userData.freePlant = e;
      this.writeStorage();
    }
  }, {
    key: "diamond",
    get() {
      null == this._userData.diamond && (this._userData.diamond = 0);
      return this._userData.diamond;
    },
    set(e) {
      this._userData.diamond = e;
      $2MoneyPanelUI.default.instance && $2MoneyPanelUI.default.instance.refreshMoneyPanel();
      this.writeStorage();
    }
  }, {
    key: "scene",
    get() {
      null == this._userData.scene && (this._userData.scene = 0);
      return this._userData.scene;
    },
    set(e) {
      this._userData.scene = e;
      this.writeStorage();
    }
  }, {
    key: "lastYear",
    get() {
      null == this._userData.lastYear && (this._userData.lastYear = 0);
      return this._userData.lastYear;
    },
    set(e) {
      this._userData.lastYear = e;
      this.writeStorage();
    }
  }, {
    key: "lastMonth",
    get() {
      null == this._userData.lastMonth && (this._userData.lastMonth = 0);
      return this._userData.lastMonth;
    },
    set(e) {
      this._userData.lastMonth = e;
      this.writeStorage();
    }
  }, {
    key: "lastDay",
    get() {
      null == this._userData.lastDay && (this._userData.lastDay = 0);
      return this._userData.lastDay;
    },
    set(e) {
      this._userData.lastDay = e;
      this.writeStorage();
    }
  }, {
    key: "isNewDay",
    value: function isNewDay() {
      var e = new Date();
      var t = this.lastYear;
      var a = this.lastMonth;
      var n = this.lastDay;
      if (e.getDate() == n && e.getMonth() == a && e.getFullYear() == t) {
        console.log("是同一天不处理");
        if (this.getHour() != this.shopHour) {
          this.getShopInfo(), console.log("刷新商店===");
        }
      } else {
        console.log("新的一天");
        this.signTimes = 0;
        this.freePlant = 0;
        this.shareReward = true;
        this.onlineNum = 0;
        this.onlineTime = 0;
        _ctor.instance.shopRefreshTimes = 0;
        this.lastYear = e.getFullYear();
        this.lastMonth = e.getMonth();
        this.lastDay = e.getDate();
        this.getShopInfo();
        this.getonlineInfo();
        this.getTaskInfo();
      }
    }
  }, {
    key: "getTimeInfo",
    value: function getTimeInfo() {
      var e = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.timeTable);
      this.timeInfo = [];
      for (var _t75 in e) {
        this.timeInfo.push(e[_t75]);
      }
    }
  }, {
    key: "getTime1Info",
    value: function getTime1Info() {
      var e = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.time1Table);
      this.time1Info = [];
      for (var _t76 in e) {
        this.time1Info.push(e[_t76]);
      }
    }
  }, {
    key: "getBwzjsInfo",
    value: function getBwzjsInfo() {
      var e = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.bwzjsTable);
      this.bwzjsInfo = [];
      for (var _t77 in e) {
        this.bwzjsInfo.push(e[_t77]);
      }
    }
  }, {
    key: "getBwzdaifuInfo",
    value: function getBwzdaifuInfo() {
      var e = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.bwzdaifuTable);
      this.bwzdaifuInfo = [];
      for (var _t78 in e) {
        this.bwzdaifuInfo.push(e[_t78]);
      }
    }
  }, {
    key: "getTaskInfo",
    value: function getTaskInfo() {
      var e = [];
      var t = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.taskTable);
      var a = Object.keys(t);
      var o = [{
        id: "001",
        progress: 0,
        plantID: $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance.rare5Array),
        type: t["001"].rewardType.slice(0, 1),
        finish: false
      }];
      for (var _n62 = 0; _n62 < a.length; _n62++) {
        var _l5 = {
          id: "",
          progress: 0,
          plantID: 0,
          type: "a",
          finish: false
        };
        _l5.id = a[_n62];
        _l5.progress = 0;
        _l5.finish = false;
        switch (t[a[_n62]].rewardType.slice(0, 1)) {
          case "a":
            _l5.type = "a";
            break;
          case "b":
            _l5.type = "b";
            break;
          case "c":
            _l5.type = "c";
            var _e127 = t[a[_n62]].rewardType.slice(1);
            var _o3 = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance["rare" + _e127 + "Array"]);
            _l5.plantID = _o3;
        }
        if (t[a[_n62]].taskType != e.length || _n62 == a.length - 1) {
          var _t79 = $2MyUtils.MyUtils.getRandomInt(0, o.length);
          e.push(o[_t79]);
          o = [];
        }
        o.push(_l5);
      }
      this.taskInfo = e;
    }
  }, {
    key: "getShopInfo",
    value: function getShopInfo() {
      var e = [];
      var t = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.shopTable);
      var a = 0;
      var o = [];
      for (var _n63 = 1; _n63 <= Object.keys(t).length; _n63++) {
        a += t[_n63].weight;
        o.push(a);
      }
      for (var _n64 = 0; _n64 < 8; _n64++) {
        var _a58 = {
          id: 0,
          type: "",
          costType: "",
          rare: 0,
          discount: 1,
          number: 0,
          cost: 0,
          bought: false
        };
        var _n65 = $2MyUtils.MyUtils.getRandomInt(1, 101);
        var _l6 = 0;
        for (; _n65 > o[_l6];) {
          _l6++;
        }
        _l6++;
        _a58.type = t[_l6].goodsType;
        _a58.rare = t[_l6].rare;
        if ("a" == _a58.type) {
          _a58.number = $2MyUtils.MyUtils.getRandomInt(t[_l6].goodsNumber[0], t[_l6].goodsNumber[1] + 1);
          if (Math.random() > .6) {
            _a58.costType = "g", _a58.cost = _a58.number * $2DataManager.default.instance["rarePrice" + _a58.rare][0];
          } else {
            _a58.costType = "d", _a58.cost = _a58.number * $2DataManager.default.instance["rarePrice" + _a58.rare][1];
          }
        } else {
          _a58.number = 1;
          if (Math.random() > .6) {
            _a58.costType = "g", _a58.cost = 20 * $2DataManager.default.instance["rarePrice" + _a58.rare][0];
          } else {
            _a58.costType = "d", _a58.cost = 20 * $2DataManager.default.instance["rarePrice" + _a58.rare][1];
          }
        }
        if (Math.random() < .05) {
          _a58.discount = .5;
        } else if (Math.random() >= .05 && Math.random() < .25) {
          _a58.discount = .8;
        } else if (Math.random() >= .25 && Math.random() < .35) {
          _a58.discount = 0;
        } else {
          _a58.discount = 1;
        }
        _a58.id = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance["rare" + _a58.rare + "Array"]);
        e.push(_a58);
      }
      this.shopInfo = e;
      this.shopHour = this.getHour();
    }
  }, {
    key: "getonlineInfo",
    value: function getonlineInfo() {
      var e = [];
      for (var _t80 = 0; _t80 < 3; _t80++) {
        var _a59 = {
          id: 0,
          type: 1,
          get: false,
          num: 0
        };
        var _n66 = Math.random();
        if (0 == _t80) {
          _a59.type = 1;
          _a59.num = 100 * $2MyUtils.MyUtils.getRandomInt(20, 31);
        } else if (1 == _t80) {
          _a59.type = 2;
          _a59.num = $2MyUtils.MyUtils.getRandomInt(30, 61);
        } else if (_n66 > .2) {
          _a59.type = 3;
          _a59.id = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance.rare1Array);
          _a59.num = 1;
        } else if (_n66 >= .2 && _n66 < .4) {
          _a59.type = 3;
          _a59.id = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance.rare3Array);
          _a59.num = 1;
        } else if (_n66 >= .4 && _n66 < .7) {
          _a59.type = 4;
          _a59.id = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance.rare4Array);
          _a59.num = 10;
        } else {
          _a59.type = 4;
          _a59.id = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance.rare5Array);
          _a59.num = 10;
        }
        e.push(_a59);
      }
      this.onlineInfo = e;
    }
  }, {
    key: "getHour",
    value: function getHour() {
      var e = new Date().getHours();
      if (e >= 0 && e < 8) {
        return 0;
      } else {
        if (e >= 8 && e < 16) {
          return 8;
        } else {
          return 16;
        }
      }
    }
  }, {
    key: "writeStorage",
    value: function writeStorage() {
      if (this._userData) {
        cc.sys.localStorage.setItem(this._userDataKey, JSON.stringify(this._userData));
      } else {
        console.log("没有初始化数据不存!");
      }
    }
  }], [{
    key: "instance",
    get() {
      null == this._instance && (this._instance = new _ctor());
      return this._instance;
    }
  }]);
  return _ctor;
}();
exports.default = def_UserDataManager;
def_UserDataManager._instance = null;